﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SMTC.BO.UserPower;
using System.Data;
using System.Text.RegularExpressions;
using SMTC.WebCommon.Common;

public partial class Common_UpdateMounterParameter : BasePage
{
    private UpdateMounterMaintenance updatemaintenance = new UpdateMounterMaintenance();
    private OneMounterMaintenance onemaintenance = new OneMounterMaintenance();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState["MounterID"] = null;
            ViewState["MounterID"]= Request.QueryString["MounterID"].ToString();
            DataSet set = onemaintenance.One_Mounter_Maintenance(ViewState["MounterID"].ToString());
            TextBoxMachineType.Text = set.Tables[0].Rows[0][0].ToString();
            TextBoxAbility.Text = set.Tables[0].Rows[0][1].ToString();
            TextBoxParameter.Text = set.Tables[0].Rows[0][2].ToString();
            TextBoxPeople.Text = set.Tables[0].Rows[0][3].ToString();
            if (set.Tables[0].Rows[0][4].ToString() == "")
                TextBoxtTime.Text = "";
            else
            {
                TextBoxtTime.Text = Convert.ToDateTime(set.Tables[0].Rows[0][4].ToString()).ToString("yyyy-MM-dd");
            }
        }
    }
    protected void ButtonCancel_Click(object sender, EventArgs e)
    {
        Response.Write("<script language=javascript>self.close()</script>");
    }
    protected void ButtonOK_Click(object sender, EventArgs e)
    {
        if (CheckAbility(TextBoxAbility.Text.ToString().Trim()) == false || IsValidParameter(TextBoxParameter.Text.ToString().Trim()) == false)
        {
            ClientScript.RegisterStartupScript(Page.GetType(), "", "UpdateFalse() ", true);
          
        }
        else 
        {
            updatemaintenance.Update_Mounter_Maintenance(ViewState["MounterID"].ToString(), int.Parse(TextBoxAbility.Text.ToString().Trim()), TextBoxParameter.Text.ToString().Trim(), TextBoxPeople.Text.ToString().Trim(), TextBoxtTime.Text.ToString().Trim());
            ViewState["MounterID"] = null;
            ClientScript.RegisterStartupScript(Page.GetType(), "", "UpdateOK()", true);
        }
    }

    protected bool CheckAbility(string ability)
    {
        int f;
        return int.TryParse(ability, out f);

    }
    protected bool IsValidParameter(string parameter)
    {
        return Regex.IsMatch(parameter, @"^[0-9]+(.[0-9]{1,2}){1}$");


    }
}